﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Serialization;

namespace Payton.WP7.Common.Model
{
    public class SNSUser : ModelBase, IEquatable<SNSUser>
    {
        public static SNSUser UnknowUser = new SNSUser()
        {
            Name = "匿名用户"
        };

        //TODO: Account
        public int AccountID { get; set; }

        //[XmlIgnore]
        //public SNSAccount Account { get; set; }

        public SNSProviderType ServiceProvider { get; set; }

        private long id;

        public long Id
        {
            get { return id; }
            set { id = value; }
        }
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string nickName;

        public string AccountName
        {
            get { return nickName; }
            set { nickName = value; }
        }

        private int province;

        public int Province
        {
            get { return province; }
            set { province = value; }
        }
        private int city;

        public int City
        {
            get { return city; }
            set { city = value; }
        }
        private string location;

        public string Location
        {
            get { return location; }
            set { location = value; }
        }
        private string description;

        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        private string url;

        public string Url
        {
            get { return url; }
            set { url = value; }
        }
        private string profile_image_url;

        public string ProfileImageUrl
        {
            get { return profile_image_url; }
            set { profile_image_url = value; }
        }
        private string domain;

        public string Domain
        {
            get { return domain; }
            set { domain = value; }
        }
        private string gender;

        //TODO 这里需要一个Converter来转换性别
        public string Gender
        {
            get { return gender; }
            set { gender = value; }
        }
        private int followers_count;

        public int FollowersCount
        {
            get { return followers_count; }
            set { followers_count = value; }
        }
        private int friends_count;

        public int FriendsCount
        {
            get { return friends_count; }
            set { friends_count = value; }
        }
        private int statuses_count;

        public int StatusesCount
        {
            get { return statuses_count; }
            set { statuses_count = value; }
        }
        private int favourites_count;

        public int FavouritesCount
        {
            get { return favourites_count; }
            set { favourites_count = value; }
        }
        private DateTime created_at;

        public DateTime CreatedTime
        {
            get { return created_at; }
            set { created_at = value; }
        }
        private bool following;

        public bool Following
        {
            get { return following; }
            set { following = value; }
        }

        private bool fans;

        public bool Fans
        {
            get { return fans; }
            set { fans = value; }
        }

        private bool verified;

        public bool Verified
        {
            get { return verified; }
            set { verified = value; }
        }

        bool self;

        public bool Self
        {
            get { return self; }
            set { self = value; }
        }

        string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        string lastStatusText;

        public string LastStatusText
        {
            get { return lastStatusText; }
            set { lastStatusText = value; }
        }

        public void UpdateDifferent(SNSUser user)
        {
            if (user == null || user.AccountName != this.AccountName)
                return;

            if (Name != user.Name)
            {
                Name = user.Name;
                RaisePropertyChanged(()=>Name);
            }

            if (Province != user.Province)
            {
                Province = user.Province;
                RaisePropertyChanged(() => Province);
            }

            if (City != user.City)
            {
                City = user.City;
                RaisePropertyChanged(() => City);
            }

            if (Location != user.Location)
            {
                Location = user.Location;
                RaisePropertyChanged(() => Location);
            }

            if (Description != user.Description)
            {
                Description = user.Description;
                RaisePropertyChanged(() => Description);
            }

            if (Url != user.Url)
            {
                Url = user.Url;
                RaisePropertyChanged(() => Url);
            }

            if (ProfileImageUrl != user.ProfileImageUrl)
            {
                ProfileImageUrl = user.ProfileImageUrl;
                RaisePropertyChanged(() => ProfileImageUrl);
            }

            if (Domain != user.Domain)
            {
                Domain = user.Domain;
                RaisePropertyChanged(() => Domain);
            }

            if (Gender != user.Gender)
            {
                Gender = user.Gender;
                RaisePropertyChanged(() => Gender);
            }

            if (FollowersCount != user.FollowersCount)
            {
                FollowersCount = user.FollowersCount;
                RaisePropertyChanged(() => FollowersCount);
            }

            if (FriendsCount != user.FriendsCount)
            {
                FriendsCount = user.FriendsCount;
                RaisePropertyChanged(() => FriendsCount);
            }

            if (Following != user.Following)
            {
                Following = user.Following;
                RaisePropertyChanged(() => Following);
            }

            if (Fans != user.Fans)
            {
                Fans = user.Fans;
                RaisePropertyChanged(() => Fans);
            }

            if (Verified != user.Verified)
            {
                Verified = user.Verified;
                RaisePropertyChanged(() => Verified);
            }

            if (Self != user.Self)
            {
                Self = user.Self;
                RaisePropertyChanged(() => Self);
            }

            if (Email != user.Email)
            {
                Email = user.Email;
                RaisePropertyChanged(() => Email);
            }

            if (LastStatusText != user.LastStatusText)
            {
                LastStatusText = user.LastStatusText;
                RaisePropertyChanged(() => LastStatusText);
            }
        }

        #region IEquatable<SNSUser> Members

        public bool Equals(SNSUser other)
        {
            if (other != null && other.ServiceProvider == this.ServiceProvider && other.AccountName == this.AccountName)
            {
                return true;
            }

            return false;
        }

        #endregion
    }

    public enum UserGender
    {
        Male,Female,Unknow
    }
}
